<template>
  <div class="detal">
    <header class="header">
      <ul>
        <li @click="$router.back()" class="iconfont icon-zuojiantou"></li>
        <li>
          <span>{{itemInfos.brand}}</span>
          <span>￥{{itemInfos.price}}</span>
        </li>
        <li class="iconfont icon-iconfontzhizuobiaozhun0257"></li>
      </ul>
    </header>
    <div class="content">
      <div class="picture">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(imgsrc,idx) in itemInfos.images" :key="idx"><img
          :src="imgsrc.bigImgUrl"
          alt
        /></van-swipe-item>
        </van-swipe>
      </div>
      <div class="details">
        <h2>{{itemInfos.name}}</h2>
        <div class="price">
          <p>￥{{itemInfos.marketPrice}}</p>
          <span>￥{{itemInfos.price}}</span>
          &nbsp;&nbsp;&nbsp;
          <span
            style="background: rgb(255, 255, 255); color: rgb(0, 0, 0); border: 0.013333rem solid rgb(0, 0, 0);"
            >{{itemInfos.discount}}</span
          >
        </div>
      </div>
      <div class="goods">
        <em class="iconfont icon-biao"></em>
        <span>预计2020/04/14发货</span>
      </div>
      <div class="countdown">
        <div class="flash">
          <p>闪购</p>
          <p>距结束01天06小时30分30秒</p>
        </div>
        <div class="promotion">
          <p>促销</p>
          <p>焕新日男装-1件7折;</p>
        </div>
      </div><div class="countdown">
        <div class="flash">
          <p>闪购</p>
          <p>距结束01天06小时30分30秒</p>
        </div>
        <div class="promotion">
          <p>促销</p>
          <p>焕新日男装-1件7折;</p>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="left" @click="$router.push('/cart')">
        <van-icon name="bag-o" :badge="plist.length" />
        <span>购物袋</span>
      </div>
      <div @click="addcart" class="center">
        加入购物车
      </div>
      <div class="right">
        立即购买
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import {mapMutations,mapState} from "vuex"
export default {
  data() {
    return {
      itemInfos: {}
    };
  },
  computed:{
    ...mapState("cart",["plist"])
  },
  created() {
    console.log(this.$route.query.id)
      axios
      .get(
        "http://www.mei.com/appapi/product/detail/v3?categoryId=2121005100000003880&productId="+this.$route.query.id
      )
      .then(res => {
        this.itemInfos = res.data.infos;
      });
  },
  methods:{
    ...mapMutations("cart",["addPlist"]),
    addcart(){
      this.addPlist({
        itemId: "3023015200003433039",
        productId: this.$route.query.id,
        categoryId: "2040204090000008105",
        glscode: "IW4-2576-100003-C",
        brand: this.itemInfos.brand,
        name: this.itemInfos.name,
        size: "M",
        price: this.itemInfos.price,
        qty: "1",
        imgUrl: this.itemInfos.images[0].bigImgUrl,
        stock: "3",
        parentProductId: "2017201799000016686",
        eventCode: "48112",
        color: "灰色",
        free: false
      })
    }
  }
};
/*
需传 categoryId =2041204190000007914
     productId =2120212099000145828 */
</script>
<style lang="scss" scoped>
.detal {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.header {
  height: .45rem;
  width: 100%;
  background: rgba(255, 255, 255, 0.9);

}
.header ul {
  display: flex;
  justify-content: space-between;
}
.header ul li:nth-child(1) {
  margin-top: .16rem;
  margin-left: .16rem;
  font-size: .16rem;
}
.header ul li:nth-child(2) {
  display: flex;
  flex-direction: column;
}
.header ul li:nth-child(3) {
  margin-top: 0.16rem;
  margin-right: 0.16rem;
  font-size: .18rem;
}
.header ul li:nth-child(2) > span:nth-child(1) {
  font-size: .16rem;
  color: black;
  font-weight: 700;
  text-align: center;
}
.header ul li:nth-child(2) > span:nth-child(2) {
  font-size: .14rem;
  color: red;
  font-weight: 700;
  text-align: center;
}
.content{
  flex:1;
  padding: 0 .2rem;
  overflow-y: auto;
}
.picture {
  width: 100%;
  img{
    max-width: 100%;
  }
}
.picture > img {
  width: 100%;
}
.details {
  width: 100%;
  padding-bottom: 0.32rem;
  overflow: hidden;
}
.details > h2 {
  margin-top: .16rem;
  font-size: .18rem;
  color: #000;
  margin-bottom: .2rem;
}
.price > p {
  color: #ccc;
  font-size: .14rem;
}
.price > span:nth-child(2) {
  color: #dd2828;
  font-size: .18rem;
  font-weight: 700;
  margin-right: .12rem;
}
.goods {
  width: 100%;
  height: .46rem;
  border-bottom: solid .01rem #ccc;
  margin-top: 0.14rem;
}
.goods > span {
  margin-left: .08rem;
}
.flash {
  width: 100%;
  height: .6rem;
  display: flex;
  border-bottom: solid 0.5px #ccc;
}
.flash > p:nth-child(1) {
  color: #666666;
  font-size: .16rem;
  margin-right: .2rem;
  line-height: .6rem;
}
.flash > p:nth-child(2) {
  color: #000;
  font-size: .16rem;
  font-weight: 600;
  line-height: .6rem;
}
.promotion {
  width: 100%;
  height: .6rem;
  display: flex;
  border-bottom: solid 0.5px #ccc;
}
.promotion > p:nth-child(1) {
  color: #666666;
  font-size: .16rem;
  margin-right: .2rem;
  line-height: .6rem;
}
.promotion > p:nth-child(2) {
  color: #dd2828;
  font-size: 0.16rem;
  font-weight: 600;
  line-height: .6rem;
}
/* .footer */
.footer{
  height: .46rem;width:100%;
  background: #fff;
  box-shadow: 0 -1px 5px #ccc;
  display: flex;
  div{
    font-weight: 900;
  }
  .left{width:.64rem;
    display: flex;
    flex-direction: column;
    line-height: 1;
    justify-content: center;
    align-items: center;
    i{font-size: .2rem;}
    span{
      font-size: .12rem;
    }
  }
  .center,.right{
    text-align: center;
    line-height: .46rem;
    flex:1;
    font-size: .16rem;
    color: red;
  }
  .center{
    border-left: .5px solid #ccc;
    border-right: .5px solid #ccc;
    color: #222;
  }
}
</style>
